var salt = sessionStorage.getItem('usersalt');
layui.config({
    base: '../../../js/',
})
var id = getQueryVariable('id');
var detail = getQueryVariable('detail');
var edit = getQueryVariable('edit');
var editCompanyId;
console.log(id)

if(id){
    $.post(url+'questionPaper/getInfo',{id:id,Token:salt},function (data) {
        if(data.code == 0){
            var data = data.data;
            $("#title").val(data.title);
            $("#examType").val(data.examType);
            $("#duration").val(data.duration);
            if(data.startTime){
                layui.use(['laydate'], function() {
                    var laydate = layui.laydate;
                    laydate.render({
                        elem: '#startTime',
                        value: new Date(data.startTime)
                    });
                    laydate.render({
                        elem: '#endTime',
                        value: new Date(data.endTime)
                    });
                })
                $(".outTime").remove()
            }else{
                $(".outTime").addClass("active");
                $("#startTime,#endTime").remove()
            }
            $("#radio").val(data.radio);
            $("#multiSelect").val(data.multiSelect);
            $("#tfng").val(data.tfng);
            $("#entId").val(data.entName);
            $("#sortType").val(data.sortType);
            $(".radio_num").text(data.radioQuestion.length);
            $(".multiSelect_num").text(data.multiSelectQuestion.length);
            $(".tfng_num").text(data.tfngQuestion.length);
            var total = data.radioQuestion.length+data.multiSelectQuestion.length+data.tfngQuestion.length;
            var typeArr = [data.radioQuestion.length,data.multiSelectQuestion.length,data.tfngQuestion.length];
            // localStorage.setItem("typeArr",typeArr);
            var choiceArr = [];
            //设置题目
            data.radioQuestion.forEach(function (item) {
                choiceArr.push(item.id)
            });
            data.multiSelectQuestion.forEach(function (item) {
                choiceArr.push(item.id)
            });
            data.tfngQuestion.forEach(function (item) {
                choiceArr.push(item.id)
            });
            // localStorage.setItem("detailchoiceArr",choiceArr);
            $(".red_box p").text("试题数：共"+total+"道题目");


        }else{
            alert(data.msg)
        }
    })
    if(detail){
        $(".add,.submit").remove();
    }
}
layui.use(['form', 'layer', 'laydate', 'table', 'multiSelect'], function() {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        formSelects = layui.formSelects,
        table = layui.table;

    /*验证登录*/
    if(!sessionStorage.getItem('username')) {
        layer.msg('请先登录');
        setTimeout("top.location.href='../../../index.html'", 1000);
    }

    /*时间选择器*/
    laydate.render({
        elem: '#startTime',
        trigger: 'click'
    });

    laydate.render({
        elem: '#endTime',
        trigger: 'click'
    });
    form.render();

    /*筛选*/
    $('#seleCheck').on('click', function() {

    });

    /*搜索*/
    $('#findscri').on('click', function() {
        var inptext = $('#inptext').val();
        var box = /\s/g;
        var param = inptext.replace(box, '');
    });
    var company;
    /*取出所有的单位*/
    function getAllDanwei() {
        $.ajax({
            url: url + 'baseEnt/getAllEnt',
            dataType: 'json',
            async: false,
            type: "POST",
            data: {},
            success: function(data) {
                $('#danwei').empty();
                if(data.code == 0) {
                    var list = data.data;
                    company = list;
                }

            },
            error: function(error) {
                console.log("获取失败");
            }
        });
    }

    getAllDanwei();

    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: zTreeOnCheck
        }
    };
    var zNodes = company;
    $.fn.zTree.init($("#danwei"), setting, zNodes);

    function getSydwVal() {
        var treeArr = [];
        var treeObj = $.fn.zTree.getZTreeObj("danwei");
        var nodes = treeObj.getCheckedNodes(true);
        for(var i = 0; i < nodes.length; i++) {
            treeArr.push(nodes[i].id); //获取选中节点的值
        }
        return treeArr;
    }
    $('#entId').click(function() {
        $('#danwei').show();
    });

    function zTreeOnCheck(event, treeId, treeNode) {
        var nval = "";
        var treeObj = $.fn.zTree.getZTreeObj("danwei");
        var nodes = treeObj.getCheckedNodes(true);
        for(var i = 0; i < nodes.length; i++) {
            nval += nodes[i].name + ",";
        }
        $('#entId').val(nval.substr(0, nval.length - 1));
    };
    /*------------tree.end------------*/

    var tableIns;

    //新增
    $(".addNews_btn").click(function() {
        $(".model").show();
    });


    //题库
    $(".subject_btn").click(function() {
        location.href = "../subject/subject.html"

    });

    //导出
    $(".export_btn").click(function() {

    });
    //导入
    $(".import_btn").click(function() {
        layer.open({
            type: 2,
            title: false,
            content: "page/404.html",
            area: ['700px', '300px']
        });
    });
})



$("body").on("click", ".add,.red_box", function () {
    location.href = "subject.html?id="+id;
});






















